package com.atguigu;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/8/7
 * <p>
 * 1. ArrayList 初始值 10, HashMap 初始值 16
 * 2. ArrayList 扩容是原来的一半，HashMap 扩容是原来的一倍 java8
 */
public class NotSafeDemo {
    public static void main(String[] args) {

//        java.util.ConcurrentModificationException
//        List<String> list = new ArrayList<>();
//        List<String> list = new Vector<>();
//        List<String> list = Collections.synchronizedList(new ArrayList<>());
        List<String> list = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 30; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 6));
                System.out.println(Thread.currentThread().getName() + "---" + list);
            }).start();
        }
    }
}
